package com.aliyun.oss.service.impl;

import com.aliyun.oss.mapper.ArticleCategoryMapper;
import com.aliyun.oss.pojo.ArticleCategory;
import com.aliyun.oss.service.ArticleCategoryService;
import com.aliyun.oss.utils.JwtUtil;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleCategoryServiceImpl implements ArticleCategoryService {
    @Autowired
    ArticleCategoryMapper articleCategoryMapper;
    @Override
    public List<ArticleCategory> selectAllArticleCategory(Integer id) {
        List<ArticleCategory> articleCategories = articleCategoryMapper.selectAllArticleCategory(id);
        return articleCategories;
    }

    @Override
    public void addArticleCategory(String authHeader, ArticleCategory articleCategory) {
        Claims claims = JwtUtil.analysisToken(authHeader);
        Integer id = (Integer) claims.get("id");
        articleCategoryMapper.addArticleCategory(id,articleCategory);
    }

    @Override
    public void updateArticleCategory(String authHeader, ArticleCategory articleCategory) {
        Claims claims = JwtUtil.analysisToken(authHeader);
        Integer id = (Integer) claims.get("id");
        articleCategoryMapper.updateArticleCategory(id,articleCategory);
    }

    @Override
    public void deleteArticleCategory(String authHeader, String id) {
        Claims claims = JwtUtil.analysisToken(authHeader);
        Integer userId = (Integer) claims.get("id");
        articleCategoryMapper.deleteArticleCategory(userId,id);
    }
}
